延續 Day 1 所寫的 addEventListener('click')
,今天再加上按下去時,要去替換已經在 CSS 裡的 .pressed
特效,並且在 100 毫秒後移除特效:
document.getElementById('green').addEventListener("click", function(){
userChosenColour = 'green'
userClickedPattern.push(userChosenColour);
console.log(userClickedPattern)
document.getElementById('green').classList.add('pressed');
setTimeout(function(){document.getElementById('green').classList.remove('pressed');}, 100);
});
遊戲開始前的畫面
接著在遊戲開始時,告訴使用者現在在第幾關:
document.addEventListener("keydown", event=> {
if (event.isComposing || event.code === 65 ) {
return;
}
//do something
var level = 1;
nextSequence()
function howManyTimes(){
// var level = 0
var level = nextSequence +=1;
}
howManyTimes()
document.getElementById('level-title').innerHTML='Level '+level;
});
完成: